from leapp.actors import Actor
from leapp.libraries.common.rpms import has_package
from leapp.models import InstalledRedHatSignedRPM
from leapp.reporting import Report, create_report
from leapp import reporting
from leapp.reporting import create_report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class Checklvm2cluster(Actor):
    """
    Check if lvm2-cluster is installed. If yes, stop upgrade
    """

    name = 'check-lvm2-cluster'
    consumes = (InstalledRedHatSignedRPM,)
    produces = (Report,)
    tags = (ChecksPhaseTag, IPUWorkflowTag)

    def process(self):
        if has_package(InstalledRedHatSignedRPM, 'lvm2-cluster'):
            create_report([
                reporting.Title('lvm2-cluster is installed, lvm2-cluster cannot be processed during upgrade'),
                reporting.Summary('lvm2-cluster affects the upgrade and needs to be uninstalled first'),
                reporting.Severity(reporting.Severity.HIGH),
                reporting.Remediation(hint='Use "yum -y remove lvm2-cluster" before "leapp preupgrade --no-rhsm" '),
                reporting.Flags([reporting.Flags.INHIBITOR])
            ])
